package com.cuz.array;

import javax.swing.*;

public class TheBestTimeToBuyAndSellStock {

    public static Integer maxProfit1(int[]prices){
        int min=Integer.MAX_VALUE;
        int res=0;
        for (int i = 0; i < prices.length; i++) {
            min=Math.min(min,prices[i]);
            res=Math.max(prices[i]-min,res);
        }
        return res;
    }

    public static void main(String[] args) {
        System.out.println(maxProfit1(new int[]{7, 1, 5, 3, 6, 4}));
    }

    public static Integer maxProfit2(int[]prices){
        int res=0;
        for (int i = 1; i < prices.length; i++) {
            if (prices[i]>prices[i-1]){
                res+=prices[i]-prices[i-1];
            }
        }
        return res;
    }
}
